﻿@using TinyForum.Web.Extensions;
@model IEnumerable<TinyForum.Web.Proxies.ServiceReference.PostDataObject>

@{
    ViewBag.Title = @Site.Settings.SiteTitle + " - All Posts";
}

<h2>@ViewBag.TopicName</h2>
<table width="100%">
    <tr>
        <th>
            Post
        </th>
        <th>
            Posted By
        </th>
        <th align="right">
            Replies
        </th>
        <th align="center">
            Latest Reply
        </th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.ActionLink(@item.Title, "DisplayPostDetail", "Post", new { id = @item.ID }, null)<br />
        </td>
        <td>
            @string.Format("{0}, {1}", @item.User.UserName, @item.DateCreated.Value)
        </td>
        <td>
            @if (@item.TotalReplies != null)
            {
                @item.TotalReplies.Value
            }
            else
            { 
                <p>0</p>
            }
        </td>
        <td>
        @if(@item.LatestReply != null && 
            @item.LatestReply.User.UserName != null && 
            @item.LatestReply.DateCreated != null)
        {
            @string.Format("{0}, {1}", @item.LatestReply.User.UserName, @item.LatestReply.DateCreated)
        }
        else
        {
            @Html.Encode("-");
        }
        </td>
        @*<td>
            @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.ID })
        </td>*@
    </tr>
}

</table>
